#include "vector.h"
#include <cmath>

const float& Vector::operator [](int i) const {
    switch(i){
    case 0:
        return m_x;
    case 1:
        return m_y;
    case 2:
        return m_z;
    default: ;
    }
}
float& Vector::operator [](int i){
    switch(i){
    case 0:
        return m_x;
    case 1:
        return m_y;
    case 2:
        return m_z;
    default: ;
    }
}

void  Vector::operator= (const Point& rhs) {
    m_x = rhs.m_x;
    m_y = rhs.m_y;
    m_z = rhs.m_z;
}
float operator* (const Vector& lhs, const Vector& rhs){
   return lhs.m_x * rhs.m_x + lhs.m_y * rhs.m_y + lhs.m_z * rhs.m_z ;
}
Vector operator* (const Vector& lhs, const float& rhs){
    return {lhs.m_x * rhs, lhs.m_y * rhs, lhs.m_z * rhs};
}
Vector operator* (const float& lhs, const Vector& rhs){
    return {rhs.m_x * lhs, rhs.m_y * lhs, rhs.m_z * lhs};
}
Vector operator^ (const Vector& lhs, const Vector& rhs){
    return {lhs.m_y * rhs.m_z - lhs.m_z * rhs.m_y, lhs.m_z * rhs.m_x - lhs.m_x * rhs.m_z, lhs.m_x * rhs.m_y - lhs.m_y * rhs.m_x};
}
Vector operator+ (const Vector& lhs, const Vector& rhs){
    return {rhs.m_x + lhs.m_x, rhs.m_y + lhs.m_y, rhs.m_z + lhs.m_z};
}
void Vector::normalized(){
    float length = std::sqrt(m_x*m_x+m_y*m_y+m_z*m_z);
    m_x = m_x/length;
    m_y = m_y/length;
    m_z = m_z/length;
}
